package com.lagou.rocketmq.task.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;


@Configuration
@ConfigurationProperties(prefix = "jedis.config")
public class JedisConfiguration {

    /**
     * 节点地址
     */
    private String host;
    /**
     * 端口号
     */
    private Integer port;
    /**
     * 密码
     */
    private String password;
    /**
     * 最大空闲连接数
     */
    private Integer maxIdle;
    /**
     * 最大连接数
     */
    private Integer maxTotal;
    /**
     * 最长等待时间
     */
    private  Integer maxWaitMillis;

    @Bean(name= "jedis.pool")
    @Autowired
    public JedisPool jedisPool(JedisPoolConfig config) {
        return new JedisPool(config, host, port, 5000, password);
    }

    @Bean
    public JedisPoolConfig jedisPoolConfig () {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(maxTotal);
        config.setMaxIdle(maxIdle);
        config.setMaxWaitMillis(maxWaitMillis);
        return config;
    }

    public void setMaxIdle(Integer maxIdle) {
        this.maxIdle = maxIdle;
    }

    public void setMaxTotal(Integer maxTotal) {
        this.maxTotal = maxTotal;
    }

    public void setMaxWaitMillis(Integer maxWaitMillis) {
        this.maxWaitMillis = maxWaitMillis;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
